/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Subnav = require("subnav");
	var aw = require("ajaxwrapper");
    var instance = {
        initComponent: function (params,widget) {
        	var subnav = new Subnav({
        		parentNode:".J-subnav",
        		model:{
        			title:"物品分类",
        			items:[{
						id:"search",
						type: "search",
						placeholder: "物品名称",
						handler: function(str){
							aw.ajax({
								url: "api/goods/search",
								data: {
									s: str,
									searchProperties: "name", 
									fetchProperties:"pkGoods,name,version,description"		
								},
								success: function(data){
									widget.get("grid").setData(data);
								}
							});
						}
            		},{
        				id: "add",
        				type: "button",
        				text: "新增",
        				handler: function(){
        					form = widget.get("form");
        					form.reset();
        					widget.hide([".J-grid"]).show([".J-form"]);
        					widget.get("subnav").hide(["add","search"]);
        				}
        			}]
        		}
        	});
        	widget.set("subnav",subnav);
        }
    };
    module.exports = instance;
});
